<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use App\Services\HtmlossService;
use App\Services\CacheService;
use App\Models\Linkslists;
use DB;

class Htmlosshanndle implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $users_id;
    protected $links_id;
    protected $created_at;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($users_id,$links_id,$created_at)
    {
        $this->users_id = $users_id;
        $this->links_id = $links_id;
        $this->created_at = $created_at;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if (empty($this->links_id)) {
            $linkslists = Linkslists::getUsersLinksSample($this->users_id);
            foreach ($linkslists as $linkslist) {
                HtmlossService::uploadHtml($linkslist->links_id,$linkslist->created_at);
                //清除链接缓存
                CacheService::removeLinksCache($linkslist->links_id);
            }
        } else {
            HtmlossService::uploadHtml($this->links_id,$this->created_at);
            //清除链接缓存
            CacheService::removeLinksCache($this->links_id);
        }
    }
}
